package com.zhika.zishi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhika.zishi.R;
import com.zhika.zishi.beans.FriendsDynamicBean;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/13.
 */
public class FriendsDynamicAdapter extends BaseAdapter {

    private Context context;

    private ArrayList<FriendsDynamicBean> friendsDynamicList;

    public FriendsDynamicAdapter(Context context,ArrayList<FriendsDynamicBean> friendsDynamicList){
        this.context = context;
        this.friendsDynamicList = friendsDynamicList;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return friendsDynamicList.get(position);
    }

    @Override
    public int getCount() {
        return friendsDynamicList.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if (convertView==null){
            view = LayoutInflater.from(context).inflate(R.layout.item_of_friends_dynamic_layout,null);
            viewHolder = new ViewHolder();
            viewHolder.headerImageView = (ImageView) view.findViewById(R.id.item_of_friends_dynamic_header_image_view);
            viewHolder.nicknameText = (TextView) view.findViewById(R.id.item_of_friends_dynamic_nickname_text);
            viewHolder.statusText = (TextView) view.findViewById(R.id.item_of_friends_dynamic_status_text);
            viewHolder.timeText = (TextView) view.findViewById(R.id.item_of_friends_dynamic_time_text);
            viewHolder.strategyNameText = (TextView) view.findViewById(R.id.item_of_friends_dynamic_strategy_name_text);
            viewHolder.pictureImageView = (ImageView) view.findViewById(R.id.item_of_friends_dynamic_picture_image_view);
            viewHolder.commentNumText =(TextView) view.findViewById(R.id.item_of_friends_dynamic_comment_text);
            viewHolder.collectNumText = (TextView) view.findViewById(R.id.item_of_friends_dynamic_collect_text);
            viewHolder.likeNumText = (TextView) view.findViewById(R.id.item_of_friends_dynamic_like_text);

            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
            resetViewHolder(viewHolder);
        }
        FriendsDynamicBean bean = (FriendsDynamicBean) getItem(position);

        //设置头像
//        viewHolder.headerImageView.setImageResource();

        viewHolder.nicknameText.setText(bean.getNickname());
        viewHolder.statusText.setText(bean.getStatusStr());
        viewHolder.timeText.setText(bean.getTimeStr());
        viewHolder.strategyNameText.setText(bean.getStrategyName());

        //设置内容图片
//        viewHolder.pictureImageView.setImageResource();

        viewHolder.commentNumText.setText(bean.getCommentNumStr());
        viewHolder.collectNumText.setText(bean.getCollectNumStr());
        viewHolder.likeNumText.setText(bean.getLikeNumStr());

        return view;
    }

    private void resetViewHolder(ViewHolder holder){
        holder.headerImageView.setImageResource(0);
        holder.nicknameText.setText(null);
        holder.statusText.setText(null);
        holder.timeText.setText(null);
        holder.strategyNameText.setText(null);
        holder.pictureImageView.setImageResource(0);
        holder.commentNumText.setText(null);
        holder.collectNumText.setText(null);
        holder.likeNumText.setText(null);
    }

    private class ViewHolder{
        private ImageView headerImageView;

        private TextView nicknameText;

        private TextView statusText;

        private TextView timeText;

        private TextView strategyNameText;

        private ImageView pictureImageView;

        private TextView commentNumText;

        private TextView collectNumText;

        private TextView likeNumText;
    }
}
